package com.lcf.study;

import java.util.LinkedList;
import java.util.List;

public class Test {

    public static void main(String[] args) {

        Module module = new Module();
        module.name = "app";

        Module module1 = new Module();
        module1.name = "recyclerView";

        Module module2 = new Module();
        module2.name = "androidx.core";
        module2.dependices = new Module[]{};

        Module module3 = new Module();
        module3.name = "textView";

        module1.dependices = new Module[]{module2};
        module3.dependices = new Module[]{};

        module.dependices = new Module[]{module1, module3};

        test(module);
    }

    public static class Module {
        public String name;
        public Module[] dependices;
    }

    public static List<String> test(Module module) {
        List<String> res = new LinkedList<>();
        res.add(module.name);
        dfs(module, res);
        return res;
    }

    public static void dfs(Module module, List<String> res) {
        if (module.dependices == null || module.dependices.length < 1) {
            return;
        }
        for (int i = 0; i < module.dependices.length; i++) {
            Module node = module.dependices[i];
            res.add(node.name);
            dfs(node, res);
        }
    }
}
